package com.goodving.guli.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import com.goodving.guli.R;
import com.goodving.guli.bt.DimPanelFragment;
import com.goodving.guli.bt.Utils;
import com.goodving.guli.bt.eventbus.EventPersonInfoUpdate;
import com.goodving.guli.bt.model.PersonInfo;
import com.goodving.guli.model.Keeper;
import com.goodving.guli.view.C3247b;
import com.goodving.guli.view.C3657a;

import de.greenrobot.event.EventBus;

/**
 * Created by john on 2015/12/24.
 */
public class SignaturePanelFragment extends DimPanelFragment {
    private PersonInfo f9960a;
    private EditText f9961b;

    protected int inflateLayout() {
        return R.layout.fragment_person_info_setting_signature;
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.f9960a = Keeper.readPersonInfo();
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View onCreateView = super.onCreateView(layoutInflater, viewGroup, bundle);
        this.f9961b = (EditText) onCreateView.findViewById(R.id.info_person_signature);
        this.f9961b.setText(this.f9960a.personSignature);
        this.f9961b.setSelection(this.f9961b.length());
        return onCreateView;
    }

    protected void onRightButtonClicked() {
        String str = this.f9960a.personSignature;
        if (TextUtils.isEmpty(this.f9961b.getText().toString().trim())) {
            this.f9960a.personSignature = C3657a.f18328f;
        } else {
            this.f9960a.personSignature = this.f9961b.getText().toString().replaceAll("\\s+", C3657a.f18328f);
        }
        if (!Utils.m8045b(this.f9960a.personSignature)) {
            C3247b.m22928a(getActivity(), (int) R.string.content_too_short, 0).show();
        } else if (this.f9960a.personSignature.equals(str)) {
            dismiss();
        } else {
            this.f9960a.setNeedSyncServer(2);
            Keeper.keepPersonInfo(this.f9960a);
            EventBus.getDefault().post(new EventPersonInfoUpdate(str));
            dismiss();
        }
    }
}
